package com.leecode;

/**
 * @Author: Aerospace
 * @Date: 2023/9/23 21:04
 * @Description: Dream begins
 */
public class removeDuplicates {
    public static void main(String[] args) {
        int[] nums = new int[]{1,1,1,2,2,3};
        removeDuplicates(nums);
    }

    public static int removeDuplicates(int[] nums) {
        int n = nums.length;
        int left = 0;
        int re = 1;
        for(int right= 1;right<n; ){
            if(nums[right]!=nums[left]){

                if(re==2){
                    nums[left] = nums[right];
                    re = 1;
                } else{
                    re = 0;
                    right++;
                }


            }else if(re < 2){
                re++;
                right++;
            }else if(re == 2){
                left = right++;

            }
        }
        return left;
    }
}
